#ifndef DYNAMIC_CODE_LOADER_H
#define DYNAMIC_CODE_LOADER_H

#include "AllocObject.h"



typedef char * (*EXT_API_Func)(char *param);
typedef void (*EXT_MODULE_FREE_PTR)(void *p);
typedef void (*EXT_MODULE_ON_INIT)(void *userdata);
typedef void (*EXT_MODULE_ON_SLEEP)(void);
typedef void (*EXT_MODULE_ON_EXIT)(void);
typedef void (*EXT_MODULE_WNDPROC)(unsigned int message, unsigned long wParam, unsigned long lParam);


class CDCodeLoader : public AllocObject
{
public:
	CDCodeLoader(void);
	~CDCodeLoader(void);

private:
	void *m_hModule;
	char *m_modulePath;
	char **m_apiNameList;
	int m_apiNum;
	void *m_apiHashTable;
	EXT_MODULE_FREE_PTR m_moduleFreeAPI;
	EXT_MODULE_ON_INIT	m_moduleInitAPI;
	EXT_MODULE_ON_SLEEP	m_moduleSleepAPI;
	EXT_MODULE_ON_EXIT	m_moduleExitAPI;
	EXT_MODULE_WNDPROC	m_moduleWndProcAPI;

private:
	void ReleaseModule();
	int LoadAPI(char **apilist, int apinum);

public:
	bool LoadModule(char *path, char **apilist, int apinum);
	void *CallAPI(char *func, char *params);
	void WndProc(unsigned int message, unsigned long wParam, unsigned long lParam);
};



#endif // DYNAMIC_CODE_LOADER_H
